<template>
	<view>
		<!-- 场馆申请 -->
		<venueApply ref="venueApply" v-if="status == 'apply'" :venueData="venueData" ></venueApply>
		<!-- 场馆详情 -->
		<venueDetail ref="venueDetail" v-if="status == 'detail'" :venueData="venueData" ></venueDetail>
	</view>
</template>

<script>
	//场馆申请
	import venueApply from '@/pagesWorkbenches/pages/venue/apply/apply.vue'
	//场馆详情
	import venueDetail from '@/pagesWorkbenches/pages/venue/detail/detail.vue'
	
	export default {
		components:{
			venueApply, venueDetail
		},
		data() {
			return {
				//场馆数据
				venueData: null,
				//状态
				status: '' //apply申请，detail详情
			}
		},
		onShow() {
			//获取场馆信息
			this.merchantVenue();
		},
		onUnload(){
			if(this.status == 'apply'){
				uni.$off("callLocationAddr");
			}
		},
		methods: {
			//获取场馆信息
			merchantVenue(){
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.$request({
					url: `/blade-merchant-app/merchant-app/venue/getVenue`,
					type: 'GET'
				}).then(res => {
					uni.hideLoading();
					//空表示场馆不存在
					if(Object.keys(res.data).length === 0){
						this.status = 'apply';
						this.$nextTick(() => {
							this.$refs.venueApply.vunueInitData()
						})
					} else {
						//重组数据，将图片转成数组
						var venueData = res.data;
						venueData.imgList = venueData.img.split(',');
						//场馆设施
						venueData.facilitiesList = venueData.facilities.split(',');
						//场馆服务
						venueData.servicesList = venueData.services.split(',');
						
						this.venueData = venueData;
						//场馆详情
						this.status = 'detail';
						this.$nextTick(() => {
							this.$refs.venueDetail.initData()
						})
					}
				}).catch(err =>{
					
				})
			},
		}
	}
</script>

<style>

</style>
